home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9451 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: email.eag.unisysgsg.com!not-for-mail
  2. From: ssadra@maltese.eag.unisysgsg.com (Daniel R. Ascheman)
  3. Newsgroups: comp.lang.c
  4. Subject: CONVERTING INTEGER TO ASCII??????
  5. Date: 11 Mar 1996 06:55:05 -0600
  6. Organization: Loral Defense Systems-Eagan, Eagan, MN  USA
  7. Message-ID: <4i17r9$2kn@maltese.eag.unisysgsg.com>
  8. NNTP-Posting-Host: maltese.eag.unisysgsg.com
  9. X-Newsreader: TIN [version 1.2 PL0]
  10.  
  11. HI all,
  12.  
  13. I need a way to convert an integer BACK to ascii so I can search for it 
  14. in a file using the strstr() function in a file. I NEED it as an integer
  15. AND as an ascii, is it possible?
  16. As you know, strstr() is a char *, char * , so I can't use an int,
  17. and itoa() does not exist in UNIX - I am in a slight bind.
  18.  
  19.  
  20. EXAMPLE:  (in semi-psuedo code)
  21.  
  22.  
  23.  
  24. char num;
  25. int the number;
  26. int dan;
  27.  
  28.  
  29. printf("Enter your number\n");
  30. fgets(num, sizeof, stdin)
  31. sscan(do conversion, get the number);
  32.  
  33.  
  34. dan = srand(the number);
  35.  
  36.  printf("the num is %d\n", dan);
  37.  
  38.  
  39.     now how do I convert int back to ascii so I can.....
  40.  
  41.  
  42.  if ((fp = fopen("filename", "r"))  == NULL) {
  43.     printf("Can't open file\n");
  44.     return(1);
  45.   }
  46.   
  47.   /* NOW, LOOK FOR NUMBER IN A FILE */
  48.  
  49.   while ((fgets(line_in_file, 132, fp)) != NULL) {  
  50.     if (strstr(line_in_file, dan) != NULL) {  
  51.     fclose(fp);
  52.       /* successful return */
  53.       return(0);
  54.     }
  55.   }     
  56.   fclose(fp);
  57.   /* non-successful return */
  58.   return(2);
  59.  
  60.  
  61. If no conversion is possible in C/UNIX, anyone have any other ideas?
  62.  
  63. I would greatly appreciate comments and possible solutions.
  64.  
  65. thanks,
  66. Dan Ascheman
  67.  
  68. <ssadra@maltese.eag.unisysgsg.com>
  69.